package cn.stylefeng.guns.sys.modular.tao.service.serviceImpl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.tao.entity.MemberSpecs;
import cn.stylefeng.guns.sys.modular.tao.mapper.MemberSpecsMapper;
import cn.stylefeng.guns.sys.modular.tao.model.params.MemberSpecsParam;
import cn.stylefeng.guns.sys.modular.tao.model.result.MemberSpecsResult;
import cn.stylefeng.guns.sys.modular.tao.service.MemberSpecsService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * vip规格表 服务实现类
 * </p>
 *
 * @author
 * @since 2019-08-07
 */
@Service
public class MemberSpecsServiceImpl extends ServiceImpl<MemberSpecsMapper, MemberSpecs> implements MemberSpecsService {

    @Autowired
    MemberSpecsMapper getMemberSpecsByLevel;
    @Override
    public void add(MemberSpecsParam param){
        MemberSpecs entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(MemberSpecsParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(MemberSpecsParam param){
        MemberSpecs oldEntity = getOldEntity(param);
        MemberSpecs newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public MemberSpecsResult findBySpec(MemberSpecsParam param){
        return null;
    }

    @Override
    public List<MemberSpecsResult> findListBySpec(MemberSpecsParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(MemberSpecsParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public MemberSpecs getMemberSpecsByLevel(String memberGrade) {
        return getMemberSpecsByLevel.getMemberSpecsByLevel(memberGrade);
    }

    @Override
    public List<MemberSpecs> getAll() {
        return getMemberSpecsByLevel.getAll();
    }

    @Override
    public MemberSpecs getMemberById(Integer id) {
        return getMemberSpecsByLevel.getMemberById( id);
    }

    private Serializable getKey(MemberSpecsParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private MemberSpecs getOldEntity(MemberSpecsParam param) {
        return this.getById(getKey(param));
    }

    private MemberSpecs getEntity(MemberSpecsParam param) {
        MemberSpecs entity = new MemberSpecs();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
